# -*- coding: utf-8 -*-
from django.db import models
from django.dispatch import dispatcher
from djangotoolbox import fields

class Wave(models.Model):
    title =  models.CharField('Wavelet Title', max_length=512, default = '<no title>')
    wave_id = models.CharField('Wave ID', max_length=64, unique = True)
    tags = fields.ListField(models.CharField(max_length=500), verbose_name ='Wavelet Tags', blank=True, null= True)
    
    def save(self, *args, **kwargs):
        self.title = self.title.replace('\t', '')
        super(Wave, self).save(*args, **kwargs)  

    class Meta:
        verbose_name = 'Wavelet'
        verbose_name_plural = 'Wavelets'
    
    def __unicode__(self):
        return "Wave_id: %s, wave title: %s, wave tags: %s" % \
            (self.wave_id, self.title, self.tags)        
     
class Level(models.Model):
    level = models.IntegerField(verbose_name = "Level", primary_key = True)
    name = models.CharField(verbose_name = 'Level name', max_length=128)
    tags = models.TextField(max_length=500, verbose_name = "Level Tags")
    
    def save(self, *args, **kwargs):
        self.name = self.name.replace('\t', '')
        self.tags = self.tags.replace('\t', '')
        super(Level, self).save(*args, **kwargs)  

    
    class Meta:
        verbose_name = 'Level'
        verbose_name_plural = 'Levels'
        
    def __unicode__(self):
        return "Level: %d. %s: %s" % (self.level, self.name, self.tags)

class Category(models.Model):
    wave_id = models.CharField('Category Wave ID', max_length=64)
    header = models.CharField('Category header', max_length = 500)
    tags = models.TextField(max_length = 500, verbose_name = "Category tags", blank = True, null = True)    

    
    def save(self, *args, **kwargs):
        self.header = self.header.replace('\t', '')
        self.tags = self.tags.replace('\t', '')
        super(Category, self).save(*args, **kwargs)  

    class Meta:
        verbose_name = 'Category'
        verbose_name_plural = 'Categories'
        
    def __unicode__(self):
        return "Category's wave: %s, title: %s, tags: %s" % \
            (self.wave_id, self.header, self.tags)
        
class ExtendedTag(models.Model):
    name = models.CharField(verbose_name = 'Tag name', max_length=128)
    tags = models.TextField(max_length=500, verbose_name = "Adding Tags")
    
    def save(self, *args, **kwargs):
        self.name = self.name.replace('\t', '')
        self.tags = self.tags.replace('\t', '')
        super(ExtendedTag, self).save(*args, **kwargs)    
    
    class Meta:
        verbose_name = 'Extended tag'
        verbose_name_plural = 'Extended tags'
        
    def __unicode__(self):
        return "Extended tag: %s, additional tags: %s" % (self.name, self.tags)
    
class Catalog(models.Model):
    path = fields.ListField(models.IntegerField(null = True), verbose_name ='Path enumeration', blank=True)
    blip_id = models.CharField('Blip_id', unique = True, max_length = 50)
    wave_id = models.CharField('Category Wave ID', max_length = 27)
    name = models.CharField('Tag name', max_length = 30)
    
    class Meta:
        verbose_name = 'Catalog\'s blip object'
        verbose_name_plural = 'Catalog\'s blip objects'
        
        
        
class ActiveLevel(models.Model):
    level = models.IntegerField(verbose_name = "Level", primary_key = True)
    name = models.CharField(verbose_name = 'Level name', max_length=128)
    tags = models.TextField(max_length=500, verbose_name = "Level Tags")
    
    def save(self, *args, **kwargs):
        self.name = self.name.replace('\t', '')
        self.tags = self.tags.replace('\t', '')
        super(ActiveLevel, self).save(*args, **kwargs)
            
    class Meta:
        verbose_name = 'Active Level'
        verbose_name_plural = 'Active Levels'
        
    def __unicode__(self):
        return "Level: %d. %s: %s" % (self.level, self.name, self.tags)

class ActiveCategory(models.Model):
    wave_id = models.CharField('Active Category Wave ID', max_length=64)
    header = models.CharField('Active Category header', max_length = 500)
    tags = models.TextField(max_length = 500, verbose_name = "Category tags", blank = True, null = True)    

    
    def save(self, *args, **kwargs):
        self.header = self.header.replace('\t', '')
        self.tags = self.tags.replace('\t', '')
        super(ActiveCategory, self).save(*args, **kwargs)  

    class Meta:
        verbose_name = 'Active Category'
        verbose_name_plural = 'Active Categories'
        
    def __unicode__(self):
        return "Category's wave: %s, title: %s, tags: %s" % \
            (self.wave_id, self.header, self.tags)
        
class ActiveExtendedTag(models.Model):
    name = models.CharField(verbose_name = 'Tag name', max_length=128)
    tags = models.TextField(max_length=500, verbose_name = "Adding Tags")
    
    def save(self, *args, **kwargs):
        self.name = self.name.replace('\t', '')
        self.tags = self.tags.replace('\t', '')
        super(ActiveExtendedTag, self).save(*args, **kwargs)    
    
    class Meta:
        verbose_name = 'Extended tag'
        verbose_name_plural = 'Extended tags'
        
    def __unicode__(self):
        return "Extended tag: %s, additional tags: %s" % (self.name, self.tags)        